import React,{Component} from 'react';
import PropTypes from 'prop-types';
import url from '../../component/posturl/BaseUrl';
import './newsMobile.less';
const prefix = 'news-mobile';
class NewsMobile extends Component{
    constructor(props){
        super();
        this.state = {
            newsSource:props.newsSource
        }
    };
    componentWillReceiveProps(nextProps){
        console.log(nextProps,'mobile');
        this.setState({
            newsSource:nextProps.newsSource
        })
    }
    render(){
        let {newsSource} = this.state;
        let newsEle = newsSource.map((value,index)=>{
            return(
                <a key={index} href={`/details?id=${value.id}&category=${value.category}`} className={prefix+'-news-container'}>
                    <div className={prefix+'-img-container'}>
                        <img src={`${url}/official/view?key=${value.images}`} alt=""/>
                    </div>
                    <div className={prefix+'-content'}>
                        <p className={prefix+'-title'}>{value.title}</p>
                        <p className={prefix+'-summary'}>{value.summary}</p>
                    </div>
                </a>
            )
        });
        return(
            <div className={prefix}>
                <h3>公司动态</h3>
                {newsEle}
            </div>
        )
    }
};
export default NewsMobile;
NewsMobile.propTypes = {
    newsSource:PropTypes.array
};